#!/usr/bin/perl
use strict;
use LWP::UserAgent;
use IO::Uncompress::Unzip qw(unzip $UnzipError) ;
use Archive::Extract;

my $baseDir = "c:/p/";

my @packages = (
  {name=>'WinMerge10'
    , url=> 'http://nchc.dl.sourceforge.net/sourceforge/winmerge/WinMerge-2.10.0-exe.zip'
    , to=> 'c:/p/downloaded/WinMerge-2.10.0-exe.zip'
    , uncompress=>'zip'
    }
  , {name=>'FreeCommander6c'
    , url=> 'http://freecommander.com/FreeCommander200806c.zip'
    , to=> 'c:/p/downloaded/FreeCommander200806c.zip'
    , uncompress=>'zip'
    }
  , {name=>'PStart'
    , url=> 'http://freecommander.com/FreeCommander200806c.zip'
    , to=> 'c:/p/downloaded/FreeCommander200806c.zip'
    }    
);


my $ua = LWP::UserAgent->new;

for (@packages) {
#   next if(-e $_->{to});
#   print 'Starting downloading ' . $_->{name}, " ...\n" ;
#   $ua->mirror($_->{url}, $_->{to}) || die "error! " . $!;
  if(exists $_->{uncompress}) {
    my $compress_method = $_->{uncompress}; 
    if($compress_method eq "zip") {
      my $ae = Archive::Extract->new( archive => $_->{to} );
      my $dest = $baseDir . $_->{name};
      print "Starting unzip ... to " . $dest ."\n";
      my $ok = $ae->extract( to => $dest );
      print "uncompress status " . $ok . "\n";
    }
  }
}





